class HorariosController < ApplicationController
  
  before_filter :login_required
  require_role 'pedagogico', :except=>[:index, :list, :todos_prt, :_alumnos]
  
  def index
    store_location
    list
    render :action => 'list'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  def list
    store_location
    @horarios = Horario.find(:all, :order=>'nombre')
    @alumnos_sin_horario = Persona.find_alumnos(:all, :conditions=>"horario_id is null")
  end
  
  def todos_prt
    @horarios = Horario.find(:all, :order=>'nombre')
    render :action=>'todos_prt', :layout=>'imprimir'
  end

  def _alumnos
    @horario = Horario.find(params[:id])
    render :partial=>'alumnos'
  end

  def new
    @horario = Horario.new
  end

  def create
    @horario = Horario.new(params[:horario])
    if @horario.save
      flash[:success] = 'Horario creado.'
      redirect_back_or_default :action => 'list'
    else
      render :action => 'new'
    end
  end

  def edit
    @horario = Horario.find(params[:id])
    render :partial=>'edit'
  end

  def update
    @horario = Horario.find(params[:id])
    if @horario.update_attributes(params[:horario])
      flash[:success] = 'Horario actualizado.'
      redirect_back_or_default :action => 'list'
    else
      render :action => 'edit'
    end
  end

  def destroy
    Horario.find(params[:id]).destroy
    redirect_back_or_default :action => 'list'
  end
end
